var downloadHtml = require("cloud/model/downloadHtml.js");
var schedule = require("node-schedule");

function getZhangFuFromWeb() {
}
module.exports = getZhangFuFromWeb;

getZhangFuFromWeb.get = function (callback) {
　　var rule = new schedule.RecurrenceRule();
　　var times = [];
　　for(var i=1; i<60; i++){
      if (i % 1 === 0) {
　　　　times.push(i);
      }
　　}
　　rule.second = times;
　　var j = schedule.scheduleJob(rule, function(){
      getData();
　　});
}

function getData() {
    // shanghai
  var url = "http://hq.sinajs.cn/list=s_sh000001";
  downloadHtml.download(url, function(data) {
    if (data) {
       eval(data);
       var Zhishu = AV.Object.extend("zhishu");
       var query = new AV.Query(Zhishu);
       query.get("54f8137ae4b0c976f03d963e", {
         success: function(zhishu) {
           // The object was retrieved successfully.
              var arr = hq_str_s_sh000001.split(",");
              arr.shift();
              zhishu.set("shanghai",arr);
              zhishu.save(null, {
                success: function(test) {
                },
                error: function(test, error) {
                }
              });
         },
         error: function(object, error) {
         }
       });
    } else {
    } 
  });
  // shenzheng
  var url = "http://hq.sinajs.cn/list=s_sz399001";
  downloadHtml.download(url, function(data) {
    if (data) {
       eval(data);
       var Zhishu = AV.Object.extend("zhishu");
       var query = new AV.Query(Zhishu);
       query.get("54f8137ae4b0c976f03d963e", {
         success: function(zhishu) {
           // The object was retrieved successfully.
              var arr = hq_str_s_sz399001.split(",");
              arr.shift();
              zhishu.set("shenzheng",arr);
              zhishu.save(null, {
                success: function(test) {
                },
                error: function(test, error) {
                }
              });
         },
         error: function(object, error) {
         }
       });
    } else {
    } 
  });

}

function test() {
  // 创建AV.Object子类.
  // 该语句应该只声明一次
  var GameScore = AV.Object.extend("GameScore");
  
  // 创建该类的一个实例
  var gameScore = new GameScore();
  gameScore.set("score", 1337);
  gameScore.set("playerName", "Sean Plott");
  gameScore.set("cheatMode", false);
  gameScore.save(null, {
    success: function(gameScore) {
      // Execute any logic that should take place after the object is saved.
      console.log('New object created with objectId: ' + gameScore.id);
    },
    error: function(gameScore, error) {
      // Execute any logic that should take place if the save fails.
      // error is a AV.Error with an error code and description.
      console.log('Failed to create new object, with error code: ' + error.description);
    }
  });
}
